package en_test

import (
	"bufio"
	// run `go env -w GOEXPERIMENT=jsonv2` to enable
	// the experimental jsonv2 support
	"encoding/json/v2"
	"fmt"
	"os"
	"testing"

	"gitcode.com/OpenDictionary/wiktionary2sql/schemas/en"
)

func TestEnSchema(t *testing.T) {
	// Test the schema
	{
		dir, _ := os.Getwd()
		fmt.Println("Current wkdir is:", dir)
	}
	file, err := os.Open("./../../test_files/all/raw-wiktextract-data.jsonl")
	if err != nil {
		t.Fatal(err)
	}
	defer file.Close()

	// Read one line at a time
	scanner := bufio.NewScanner(file)
	scanner.Buffer([]byte{}, 4096000000)
	for scanner.Scan() {
		line := scanner.Text()
		// Deserialize the line
		var word_data en.WordData
		if err := json.Unmarshal([]byte(line), &word_data); err != nil {
			t.Fatal(err)
		}
		// // Prettily print `word_data`
		// b, err := json.MarshalIndent(word_data, "", "  ")
		// if err != nil {
		// 	t.Fatal(err)
		// }
		// fmt.Println(string(b))
	}
	if err := scanner.Err(); err != nil {
		t.Fatal(err)
	}
}
